import fractions

# patterns:
# 2 2 2 3
# 3 3 3
# 4 5
# 1 2 2 2 2

def all_perms(str):
	if len(str) <= 1:
		yield str
	else:
		for perm in all_perms(str[1:]):
			for i in range(len(perm)+1):
				yield perm[:i] + str[0:1] + perm[i:]

def consecutive(list):
	gcds = []

	gcd = list[0]
	for i in list:
		gcd = fractions.gcd(gcd, i)
	
	count = 0.0
	for i in list:
		count += 1
		if float(i) / float(gcd) != count:
			return False
	return True

list = []

prange = []
for i in range(1, 10):
	prange.append(str(i))

for perm in all_perms(prange):
	if consecutive([int("".join(perm[0:2])), int("".join(perm[2:4])), \
		int("".join(perm[4:6])), int("".join(perm[6:9]))]):
		list.append(int("".join(perm)))
		continue
	if consecutive([int("".join(perm[0:3])), int("".join(perm[3:6])), \
		int("".join(perm[6:9]))]):
		list.append(int("".join(perm)))
		continue
	if consecutive([int("".join(perm[0:4])), int("".join(perm[4:69]))]):
		list.append(int("".join(perm)))
		continue
	if consecutive([int("".join(perm[0:1])), int("".join(perm[1:3])), \
		int("".join(perm[3:5])), int("".join(perm[5:7])), \
		int("".join(perm[7:9]))]):
		list.append(int("".join(perm)))
		continue





print max(list)
